/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package phd.dupenois.es.nplusn;

/**
 *
 * @param <T>
 * @author mpd209
 */
public class Baseline<T extends Number> {
    private Objective<T> objective;
    private T value;
    public Baseline(Objective<T> objective, T value){
        if(!objective.isValueValid(value))
            throw new IllegalArgumentException("Value "+value+" is of an invalid type");
        this.objective =objective;
        this.value = value;
    }

    /**
     * @return the objective
     */
    public Objective<T> getObjective() {
        return objective;
    }

    /**
     * @return the value
     */
    public T getValue() {
        return value;
    }

    public boolean isObjectiveResultAboveBaseline(ObjectiveResult<T> result){
        boolean valid = false;
        T otherVal = result.getValue();
        boolean isMinimise = this.objective.isMinimise();
        if(this.value instanceof Integer){
            valid = ((isMinimise&&this.value.intValue() >= otherVal.intValue())||
                ((!isMinimise)&&this.value.intValue() <= otherVal.intValue()));
        }else if(this.value instanceof Double){
            valid = ((isMinimise&&this.value.doubleValue() >= otherVal.doubleValue())||
                ((!isMinimise)&&this.value.doubleValue() <= otherVal.doubleValue()));
        }else if(this.value instanceof Float){
            valid = ((isMinimise&&this.value.floatValue() >= otherVal.floatValue())||
                ((!isMinimise)&&this.value.floatValue() <= otherVal.floatValue()));
        }else if(this.value instanceof Long){
            valid = ((isMinimise&&this.value.longValue() >= otherVal.longValue())||
                ((!isMinimise)&&this.value.longValue() <= otherVal.longValue()));
        }else if(this.value instanceof Short){
            valid = ((isMinimise&&this.value.shortValue() >= otherVal.shortValue())||
                ((!isMinimise)&&this.value.shortValue() <= otherVal.shortValue()));
        }else if(this.value instanceof Byte){
            valid = ((isMinimise&&this.value.byteValue() >= otherVal.byteValue())||
                ((!isMinimise)&&this.value.byteValue() <= otherVal.byteValue()));

        }
        return valid;

    }

}
